var foodorderiteminfoManager;
var foodorderiteminfoItemPageOpen;
var foodorderiteminfoItem;

function initFoodOrderItemInfoManager(){
	var colimnsArray = [];
	
		colimnsArray.push({
			display : '订餐号',
			name : 'orderId',
			align : 'left',
			showTitle : true,
			minWidth : 50,
			align : "center",
			editor: { type: 'text'},
			isSort : false
		});
		colimnsArray.push({
			display : '时间',
			name : 'time',
			align : 'left',
			showTitle : true,
			minWidth : 50,
			align : "center",
			type:'date',
			format : 'yyyy-MM-dd hh:mm:ss',
			render : dateRenderFun,
			editor: { type: 'date'},
			isSort : false
		});
		colimnsArray.push({
			display : '状态',
			name : 'state',
			align : 'left',
			showTitle : true,
			minWidth : 50,
			align : "center",
			editor: { type: 'text'},
			isSort : false
		});
		colimnsArray.push({
			display : '描述',
			name : 'desc',
			align : 'left',
			showTitle : true,
			minWidth : 50,
			align : "center",
			editor: { type: 'text'},
			isSort : false
		});
	
	var menu = $.ligerMenu({ width: 120, items:
		[
			{ text: '增加', click: function(){openFoodOrderItemInfoItemPage('create',"新增")}, icon: 'add' },
			{ line: true },
			{ text: '修改', click: function(){openFoodOrderItemInfoItemPage('edit',"编辑")} },
			{ line: true },
			{ text: '查看', click: function(){openFoodOrderItemInfoItemPage('show',"查看")} }
		]
	}); 
	
	return window['g'] = jQuery("#maingrid").ligerGrid({
		height : '100%',
		url:'/admin/food/foodOrderItemInfo/ajaxList.do',
		columns : colimnsArray,
		pageSize : 10,
		rownumbers : true,
		toolbar : {
			items : [ {
				text : '保存',
				click : saveUpdateFoodOrderItemInfoManager,
				icon : 'modify'
			}, {
				line : true
			}, {
				text : '增加',
				click : function(){openFoodOrderItemInfoItemPage('create',"新增")},
				icon : 'add'
			}, {
				line : true
			}]
		},
		onContextmenu : function (parm,e)
        {
			foodorderiteminfoItem = parm.data;
	        menu.show({ top: e.pageY, left: e.pageX });
	        return false;
        },
        enabledEdit: true, 
        isScroll: false, 
        rownumbers:true
	});
};

function saveUpdateFoodOrderItemInfoManager(item){
	var data = foodorderiteminfoManager.getUpdated();
	if(data.length == 0){
		$.ligerDialog.warn("您还未做任何修改哦!");
		return;
	}
	doSaveFoodOrderItemInfos(data);
};
function doSaveFoodOrderItemInfos(newData,add){
	jQuery.ajax({
		url:'/admin/food/foodOrderItemInfo/saveOrUpdate.do',
		data:{json:JSON.stringify(newData)},
		dataType:'json',
		type:'post',
		success:function(data){
			if(data.sucessList.length > 0){
				$.ligerDialog.success('恭喜,已经保存成功!');
				tip = $.ligerDialog.tip({ title: '提示信息', content: '恭喜,已经保存'+data.sucessList.length+'条记录!' });
				foodorderiteminfoManager.loadServerData({pagesize:10});
				foodorderiteminfoItemPageOpen.hidden();
			}else{
				if(data.msg){
					tip = $.ligerDialog.tip({ title: '提示信息', content: data.msg });
				}else{
					tip = $.ligerDialog.tip({ title: '提示信息', content: '网络异常,没有保存成功!' });
				}
			}
		},
		error:function(){
			$.ligerDialog.error("网络发生异常,请稍后再试!");
		}
	});
};
/**
 * 
 * @param item
 * @param target
 */
function openFoodOrderItemInfoItemPage(target,titleName){
	jQuery.ajax({
		url:'/admin/food/foodOrderItemInfo/'+target+'.do',
		data:{id:(foodorderiteminfoItem?foodorderiteminfoItem.id:0)},
		dataType:'text',
		type:'post',
		success:function(data){
			if(data){
				jQuery("#openDiv").html(data);
				foodorderiteminfoItemPageOpen = $.ligerDialog.open({ target: $("#openDiv"),isResize:true,title:titleName,width:450 });
			}
		},
		error:function(){
			$.ligerDialog.error("网络发生异常,请稍后再试!");
		}
	});
};

jQuery(function() {
	foodorderiteminfoManager = initFoodOrderItemInfoManager();
    jQuery("#pageloading").hide();
});